﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Temp.Controller;
using Temp.Model;
using Temp.View;

namespace Temp
{
    class Planner
    {
        private OntologyController oc;
        private EventController ec;
        private StoryNodeController sc;
       
        private DialogueView dv;
        private DialogueController dc;
        private List<string> listActivity;
        private StoryNode currentStoryNode;
      //  private Event currentEvent;

        public bool dialogueFinished { get; set; }

        public Planner(DialogueView dv ,List<string> listActivity) {
            //oc = new OntologyController();
            ec = new EventController();
            dc = new DialogueController();
            sc = new StoryNodeController();
        
            dialogueFinished = false; 

            this.dv = dv;
            this.listActivity = listActivity;
         //   currentStoryNode = sc.getStoryNode(1); // init to beginning of story; 
        }
        
        public void triggerEvent(int id, string type) {
            //int eventId = oc.getEventId(id,type);
            //currentEvent = ec.getEvent(eventId);
            //System.Diagnostics.Debug.WriteLine(currentEvent.type);
            //if (currentEvent.type == "DIALOGUE") {
                /*
                List<Dialogue> listDialogue = dc.getDialogue(currentEvent.idDialogue);
                List<Conversation> listC = new List<Conversation>();
                foreach (Dialogue d in listDialogue) {
                    System.Diagnostics.Debug.WriteLine("option t/f" + d.hasOption);
                    if (d.hasOption == 1)
                    {
                        List<Option> listOption = optC.getOptions(d.fakeDialogueId);
                        Conversation c = new Conversation(d.name, d.dialogue, 'T');// listOption);
                        listC.Add(c);
                    }
                    else
                    {
                        Conversation c = new Conversation(d.name, d.dialogue, 'T');// null);
                        listC.Add(c);
                    }
                    
                }
                dv.listDialogue.Clear();
                //dv.listDialogue = listC;
                dv.modifyListDialogue();
                dv.isShowing = true;        
          }*/

        }
        
        /*
        public void reevaluateStoryPath() {
            List<Ontology> listChildNodes = oc.getChildNodes(currentStoryNode.idStoryNode);
            List<Criteria> listCriteria; 
            foreach (Ontology o in listChildNodes) {
                listCriteria = cc.getCriteria(o.idObj2);
                if (compareCriteriaToActivity(listCriteria)) {
                    currentStoryNode = sc.getStoryNode(o.idObj2);
                    break;
                }
            }
            System.Diagnostics.Debug.WriteLine("CURRENT STORY IS" + currentStoryNode);
        }
        
        public void Update() {
            if (dialogueFinished) {
                System.Diagnostics.Debug.WriteLine("EVENT NAME: " + currentEvent.name);
                listActivity.Add(currentEvent.name);
                reevaluateStoryPath();
                dialogueFinished = false;
                System.Diagnostics.Debug.WriteLine("Current Story:" + currentStoryNode.name);
            }
        }
        /*
        private bool compareCriteriaToActivity(List<Criteria> listCriteria) {
            Criteria c;
            for (int i = 0; i < listCriteria.Count; i++) {
                c = listCriteria[0];
                foreach (string s in listActivity) {
                    if (c.name == s) {
                        listCriteria.Remove(c);
                    }
                }

            }

            if (listCriteria.Count == 0) {
                return true;
            }
            else
            {
                return false;
            }
        }
         */
    }
}
